package com.lzw.demo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.Collection;
import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by lzw on 2017/6/25.
 */

public class VedioAdapter extends RecyclerView.Adapter<VedioAdapter.ViewHolder> {
    private Context context;
    private List<VedioBean.ListBean> data;

    public VedioAdapter(Context context, List<VedioBean.ListBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.vedio_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        VedioBean.ListBean listBean = data.get(position);
        String vedioUrl = listBean.getVideo().getVideo().get(0);
        Log.d("info","---------------"+vedioUrl);
        String text = listBean.getText();
        holder.jcVideoPlayerStandard.setUp(vedioUrl, JCVideoPlayer.SCREEN_LAYOUT_NORMAL,text);
        Picasso.with(context).load(listBean.getVideo().getThumbnail().get(0)).into(holder.jcVideoPlayerStandard.thumbImageView);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void addAll(Collection collection){
        data.addAll(collection);
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private JCVideoPlayerStandard jcVideoPlayerStandard;
        public ViewHolder(View itemView) {
            super(itemView);
            jcVideoPlayerStandard = (JCVideoPlayerStandard) itemView.findViewById(R.id.videoplayer);
        }
    }
}
